package com.wuyou.simple;

import java.util.Arrays;

/**
 * @author yh.zhang
 * @description 88. 合并两个有序数组
 * @date 2023/11/22 9:22
 */
public class Merge {

    public static void main(String[] args) {
        int[] nums1 = {1,2,3,0,0,0};
        int m = 3;
        int[] nums2 = {2,5,6};
        int n = 3;
        solution_1(nums1, m, nums2, n);
    }

    public static void solution_1(int[] nums1, int m, int[] nums2, int n) {
        int[] temp = Arrays.copyOf(nums1, nums1.length);
        int index1 = 0, index2 = 0;
        for (int i = 0; i < nums1.length; i++) {
            if (index1 < m && index2 < n) {
                if (temp[index1] <= nums2[index2]) {
                    nums1[i] = temp[index1++];
                } else {
                    nums1[i] = nums2[index2++];
                }
            }else if (index1 < m) {
                nums1[i] = temp[index1++];
            } else {
                nums1[i] = nums2[index2++];
            }
        }
        System.out.println();
    }

}
